var fs = require('fs');
var ejs;
var compiled;
var tplData;

module.exports = function (file, opts) {
	ejs = require(file);
	return {
		prepare: function (data, done) {
			var str = fs.readFileSync(__dirname + (opts && opts._with === false ? '/tpl_escaped_without_with.ejs': '/tpl_escaped.ejs'), 'utf8');
			tplData = data;
			compiled = ejs.compile(str, opts);
			done();
		},
		prepareUnescaped: function (data, done) {
			var str = fs.readFileSync(__dirname + (opts && opts._with === false ? '/tpl_unescaped_without_with.ejs': '/tpl_unescaped.ejs'), 'utf8');
			tplData = data;
			compiled = ejs.compile(str, opts);
			done();
		},
		step: function (done) {
			var html = compiled(tplData);
			done(undefined, html);
		}
	}
};